class Solution {
public:
    int maximumBeauty(vector<int>& nums, int k) {
        int ans=0;
        sort(nums.begin(),nums.end());
        for(int left=0,right=0;right<nums.size();++right)
        {
            while(nums[right]-2*k>nums[left])
                ++left;
            ans=max(ans,right-left+1);
        }
        return ans;
    }
};
